package com.zzq.controller;

import com.zzq.domain.search.PhotoSearchParamet;
import com.zzq.domain.search.ShootRecordSearchParament;
import com.zzq.result.SmileResult;
import com.zzq.service.ClientWxPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;

@RestController
@RequestMapping("/client/pay")
@Api(value = "客户端支付接口控制",tags = {"客户端支付接口控制"})
public class ClientWxPayController {


    @Autowired
    ClientWxPayService wxPayService;

    @PostMapping("/generate/record")
    @ApiOperation("生成微信订单")
    public SmileResult generateRecord(@RequestBody ShootRecordSearchParament photoSearchParamet) throws Exception {
      return   wxPayService.generateRecord(photoSearchParamet);

    }

    @GetMapping("/record/list")
    @ApiOperation("支付记录")
    public SmileResult recordlist(){
        return   wxPayService.recordList();
    }




    @PostMapping("/notify")
    public String notify(HttpServletRequest request) throws IOException {
        // 读取请求内容
        BufferedReader br = request.getReader();
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        br.close();

        // 处理微信支付通知数据
        String notifyData = sb.toString();
        // 调用业务方法处理通知数据
        // 例如，你可以使用第三方的微信支付SDK来解析和处理通知数据

        // 返回响应给微信服务器
        return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
    }
}
